/*
 *  ptclRecvData.h
 *  serialExample
 *
 *  Created by Motoi Ishibashi on 11/02/28.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef _PTCLT_RECV_DATA_H
#define _PTCLT_RECV_DATA_H

#include <ofMain.h>
#include <ofThread.h>
#include "ofxDaito.h"
#include "ball.h"
#include "flyingBall.h"
#include "checkPoint.h"
#include "realBall.h"

#define PTCL_RECV_MAXBUFFER 10

class ptclRecvData : public ofThread {
public:
	ptclRecvData();
	~ptclRecvData();
	
	void setup(ofSerial* s, vector<ball> & _balls, vector<flyingBall> & _flyingBalls,
			   vector<checkPoint*> & _checkPoints, vector<realBall*> & _realBalls){
		serial = s;
		balls = _balls;
		flyingBalls = _flyingBalls; 
		checkPoints = _checkPoints;
		realBalls = _realBalls;
	}
	
	void threadedFunction();
	
	void sendToMaxPatch(int _ballID, int _checkPointID, float _speed);
	void sendToCheckPoints(int _ballID, int _checkPointID, float _speed);
	void sendToVisualizer(int _ballID, int _checkPointID, float _speed);
	vector<realBall*> realBalls; // すんません、ここわかりません。
		
private:
	ofSerial* serial;
	unsigned char recvBuffer[PTCL_RECV_MAXBUFFER];
	int bufferIndex;
	bool bWaitHeader;
	void parseCommand();
	vector<ball> balls;
	vector<flyingBall> flyingBalls;
	vector<checkPoint*> checkPoints;
	
	
};

#endif

